<template>
    <div class="main-container">
        <div class="mian-panel">
            <div class="login-container">
                <span class="mian-text">后台登录系统</span>
                <a-form :model="loginForm" name="basic" autocomplete="off" @finish="onFinish"
                    @finishFailed="onFinishFailed">
                    <a-form-item label="" name="username" :rules="[{ required: true, message: '请输入邮箱！' }]">
                        <a-input class="custom-input" v-model:value="loginForm.username" size="large" placeholder="邮箱" />

                    </a-form-item>
                    <a-form-item label="" name="password" :rules="[{required: true, message: '请输入密码！' }]">
                        <a-input-password class="custom-input-password" v-model:value="loginForm.password" size="large"
                            placeholder="密码" />
                    </a-form-item>
                    <a-form-item>
                        <a-button type="primary" class="login-btn" html-type="submit" :loading="loginLoading">登录</a-button>
                    </a-form-item>
                </a-form>
            </div>
            <div class="more-container">
                <a-space size="2px">
                    <router-link class="more-text" to="/register">注册</router-link>
                    <a-divider type="vertical" />
                    <a class="more-text" href="javascript:void(0);">忘记密码</a>
                </a-space>
            </div>
        </div>
    </div>
</template>

<script setup>
import { login } from '@/api/user';
import store from '@/store';
import {
    ref,
    reactive
} from 'vue';
const loginLoading = ref(false);
const loginForm = reactive({
    username: '',
    password: ''
});
const onFinish = values => {
    loginLoading.value = true;
    login(loginForm).then((response) => {
        if (response.code === 200) {
            setTimeout(() => {
                loginLoading.value = false;
            }, 700);
            const token = response.data.token;
            const user = JSON.stringify(response.data);
            store.dispatch('SetToken', token);
            store.dispatch('LoginIn', user);
        } else {
            loginLoading.value = false;
        }
    })
    console.log('Success:', values);
};
const onFinishFailed = errorInfo => {
    console.log('Failed:', errorInfo);
};
</script>

<style lang="scss" scoped>
.main-container {
    width: 100vw;
    height: calc(100vh);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #e8eaf2;
    background-position: center;
    background-size: cover;
    box-shadow: rgba(0, 0, 0, 0.05) 0px 0.5rem 2rem;

    .mian-panel {
        max-width: 450px;
        width: 100%;
        margin: auto;

        .login-container {
            display: flex;
            flex-direction: column;
            justify-content: center;
            padding: 1.5rem 1.5rem 0 1.5rem;
            background-color: #fff;
            border-radius: .25rem .25rem 0 0;

            .custom-input {
                height: calc(1.5em + .75rem + 2px);
                padding: .375rem .75rem;
                font-size: 1rem;
                font-weight: 400;
                line-height: 1.5;
                color: #495057;
                background-color: #f0f3f8;
                background-clip: padding-box;
                border-radius: .25rem;

                &::placeholder {
                    background-color: #f0f3f8;
                    color: #6c757d;
                }
            }

            .custom-input-password {
                height: calc(1.5em + .75rem + 2px);
                padding: .375rem .75rem;
                font-size: 1rem;
                font-weight: 400;
                line-height: 1.5;
                color: #495057;
                background-color: #f0f3f8;
                background-clip: padding-box;
                border-radius: .25rem;

                &:deep(.ant-input) {
                    background-color: #f0f3f8;

                    &::placeholder {
                        background-color: #f0f3f8;
                        color: #6c757d;
                    }
                }
            }

            .mian-text {
                font-size: 2.25rem;
                margin-bottom: 2.5rem;
                text-align: center;
                color: #343a40;
            }

            .login-btn {
                height: 100%;
                width: 100%;
                text-align: center;
                border-radius: .25rem;
                color: #fff;
                background-color: #0665d0;
                border-color: #0665d0;
                font-size: 1rem;
                line-height: 1.5;
                padding: .375rem .75rem;

                &:hover {
                    background-color: #0553ab;
                    border-color: #054d9e;
                }
            }
        }

        .more-container {
            background-color: #f8f9fa;
            text-align: left;
            padding-left: 1.5rem;
            padding-right: 1.5rem;
            padding: 1rem;
            border-radius: 0 0 .25rem .25rem;

            .more-text {
                color: #6c757d;
                font-size: .875rem;

                &:hover {
                    color: #3d4246;
                }
            }
        }
    }

}
</style>
